
double hexstr_to_dec(hex)
char hex[];
{
    int count1,count2,count3;
    double y;
    int z[11] = {0,0,0,0,0,0,0,0,0,0};
    double x[11] =
        {
        1,                    /* 0x000000001 times X ( 0 - 15 ) */
        16,                   /* 0x000000010 """"""""""""""""   */
        256,                  /* 0x000000100 """"""""""""""""   */
        4096,                 /* 0x000001000 """"""""""""""""   */
        65536,                /* 0x000010000 """"""""""""""""   */
        1048576,              /* 0x000100000 """"""""""""""""   */
        16777216,             /* 0x001000000 """"""""""""""""   */
        268435456,            /* 0x010000000 """"""""""""""""   */
        4294967296,           /* 0x100000000 """"""""""""""""   */
        };
    y = 0;
    count1 = count2 = count3 = 0;
    while (hex[count1] != '\0')
        count1 ++;
    while (count2 < count1)
        {
        if (hex[count2] >= '0' && hex[count2] <= '9')
            {
            z[count3] = hex[count2] - '0';
            count3++;
            }
        if (hex[count2] >= 'A' && hex[count2] <= 'F')
            {
            z[count3] = hex[count2] - 'A' + 10;
            count3 ++;
            }
        count2++;
        }
    count2 = 0;
    count1 = count3 - 1;
    while ( count2 < count3 )
        {
        y = y + z[count2] * x[count1];
        count1-- ;
        count2++;
        }
    return(y);
}

double binstr_to_dec(bin)
char bin[];
{
    int count1,count2,count3,count4;
    double y;
    double x[20] =
        {
        1,                /* 0000 0000 0000 0001 */
        2,                /* 0000 0000 0000 0010 */
        4,                /* 0000 0000 0000 0100 */
        8,                /* 0000 0000 0000 1000 */

        16,               /* 0000 0000 0001 0000 */
        32,               /* 0000 0000 0010 0000 */
        64,               /* 0000 0000 0100 0000 */
        128,              /* 0000 0000 1000 0000 */

        256,              /* 0000 0001 0000 0000 */
        512,              /* 0000 0010 0000 0000 */
        1024,             /* 0000 0100 0000 0000 */
        2048,             /* 0000 1000 0000 0000 */

        4096,             /* 0001 0000 0000 0000 */
        8192,             /* 0010 0000 0000 0000 */
        16384,            /* 0100 0000 0000 0000 */
        32768,            /* 1000 0000 0000 0000 */
        };
    count1 = count2 = count3 = count4 = 0;
    y = 0;
    while (bin[count4] != '\0')
        {
        if (bin[count4] >= '0' && bin[count4] <= '1')
            count1++;
        count4++;
        }
    count3 = count1 - 1;
    while (count2 < count1)
        {
        if ( bin[count2] == '1' )
            y = y + x[count3];
        count3--;
        count2++;
        }
    return(y);
}

double octstr_to_dec(oct)
char oct[];
{
    int count1,count2,count3;
    double y;
    int z[14] = {0,0,0,0,0,0,0,0,0,0,0};
    double x[14] =
        {
        1,
        8,
        64,
        512,
        4096,
        32768,
        262144,
        2097152,
        16777216,
        134217728,
        1073741824
        };
     count1 = count2 = count3 = 0;
     y = 0;
     while (oct[count1] != '\0')
        count1++;
     while (count2 < count1)
        {
        if (oct[count2] >= '0' && oct[count2] <= '7')
            {
            z[count3] = oct[count2] - '0';
            count3++;
            }
        count2++;
        }
     count2 = 0;
     count1 = count3 - 1;
     while (count2 < count3)
        {
        y = y + z[count2] * x[count1];
        count1 --;
        count2 ++;
        }
     return(y);
}

double decstr_to_dec(dec)
char dec[];
{
    int count1,count2,count3;
    double y;
    int z[12] = {0,0,0,0,0,0,0,0,0,0};
    double x[12] =
        {
        1,
        10,
        100,
        1000,
        10000,
        100000,
        1000000,
        10000000,
        100000000,
        1000000000
        };
    count1 = count2 = count3 = 0;
    y = 0;
    while (dec[count1] != '\0')
        count1++;
    while (count2 < count1)
        {
        if (dec[count2] >= '0' && dec[count2] <= '9')
            {
            z[count3] = dec[count2] - '0';
            count3++;
            }
        count2 ++;
        }
    count2 = 0;
    count1 = count3 - 1;
    while (count2 < count3)
        {
        y = y + z[count2] * x[count1];
        count1--;
        count2++;
        }
    return(y);
}

dec_to_decstr(num,str)
double num;
char str[];
{
    int count1,count2,count3,a;
    char *p;
    double x[12] =
        {
        1,
        10,
        100,
        1000,
        10000,
        100000,
        1000000,
        10000000,
        100000000,
        1000000000,
        };
    count1 = count2 =count3 = 0;
    for (a=0; a <= 9; a++)
       if (num >= x[a])
          {
          count1 = a;
          count3 = a;
          }
    while (count2 <= count1)
        {
        p = &str[count2];
        for (a=0; a <= 9; a++)
            if ( num >= a*x[count3] && num < (a+1)*x[count3])
                {
                *p = a + '0';
                num = num - a*x[count3];
                }
        count3--;
        count2++;
        }
    p = &str[count2];
    *p = '\0';
}

dec_to_hexstr(num,str)
double num;
char str[];
{
    int count1,count2,count3,a;
    char *p;
    double y;
    double x[12] =
        {
        1,
        16,
        256,
        4096,
        65536,
        1048576,
        16777216,
        268435456,
        4294967296
        };
    count1 = count2 = count3 = 0;
    for (a=0; a <= 7; a ++)
        if (num >= x[a])
            {
            count1 = a;
            count3 = a;
            }
    while (count2 <= count1)
        {
        p = &str[count2];
        for (a=0; a <= 15; a++)
            if (num >= a*x[count3] && num < (a+1)*x[count3])
                {
                if ( a <= 9 )
                    *p = a + '0';
                else
                    *p = a - 10 + 'A';
                num = num - a*x[count3];
                }
        count3--;
        count2++;
        }
   p = &str[count2];
   *p = '\0';
}

dec_to_octstr(num,str)
double num;
char str[];
{
    int count1,count2,count3,a;
    char *p;
    double x[14] =
        {
        1,
        8,
        64,
        512,
        4096,
        32768,
        262144,
        2097152,
        16777216,
        134217728,
        1073741824
        };
    count1 = count2 = count3 = 0;
    for (a=0; a <= 10; a++)
        if (num >= x[a] )
            {
            count1 = a;
            count3 = a;
            }
    while (count2 <= count1)
        {
        p = &str[count2];
        for (a=0; a <=7; a++)
            if (num >= a*x[count3] && num < (a+1)*x[count3])
                {
                *p = a + '0';
                num = num - a*x[count3];
                }
        count3--;
        count2++;
        }
    p = &str[count2];
    *p = '\0';
}

dec_to_binstr(num,str)
double num;
char str[];
{
    int count1,count2,count3,a;
    char *p;
    double x[] =
        {
        1,
        2,
        4,
        8,
        16,
        32,
        64,
        128,
        256,
        512,
        1024,
        2048,
        4096,
        8192,
        16384,
        32768,
        };
    count1 = count2 = count3 = 0;
    for (a = 0; a <= 15; a++)
        if (num >= x[a])
            {
            count1 = a;
            count3 = a;
            }
    while (count2 <= count1)
        {
        p = &str[count2];
        for (a = 0; a <= 1; a ++)
            if (num >= a*x[count3] && num < (a+1)*x[count3])
                {
                *p = a + '0';
                num = num - a*x[count3];
                }
        count3--;
        count2++;
        }
    p = &str[count2];
    *p = '\0';
}

